package com.gs.SynAntiWandering.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gs.SynAntiWandering.R;
import com.gs.SynAntiWandering.adapter.AddTagAdapter;
import com.gs.SynAntiWandering.db.dto.TagDto;

import java.util.List;

public class AddTagDialog extends BaseDialog {

    private Context context;
    private List<TagDto> list;
    private TextView tvAllCheck;
    private AddTagAdapter adapter;

    public AddTagDialog(@NonNull Context context, List<TagDto> list, OnOkListener onOkListener) {
        super(context, R.style.custom_dialog);
        this.context = context;
        this.list = list;
        this.onOkListener = onOkListener;
    }

    @Override
    public void refreshView() {

    }

    @Override
    public void initView() {
        findViewById(R.id.iv_close).setOnClickListener(v -> dismiss());
        findViewById(R.id.btnCancel).setOnClickListener(v -> dismiss());
        findViewById(R.id.btnOk).setOnClickListener(v -> {
            onOkListener.onOkListener();
            dismiss();
        });
        tvAllCheck = findViewById(R.id.tv_all_check);
        RecyclerView recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        adapter = new AddTagAdapter(context, list, R.layout.rvitem_add_tag);
        recyclerView.setAdapter(adapter);
        tvAllCheck.setOnClickListener(v -> {
            tvAllCheck.setSelected(!tvAllCheck.isSelected());
            adapter.setAllCheck(tvAllCheck.isSelected());
        });
    }

    @Override
    public int getLayoutId() {
        return R.layout.dialog_add_tag;
    }

    @Override
    public void show() {
        super.show();
        Window window = this.getWindow();
        window.setGravity(Gravity.CENTER);
    }

    private OnOkListener onOkListener;

    public interface OnOkListener {
        void onOkListener();
    }
}
